package sistemioperativi.matrice.es5;
import java.util.Arrays;
import java.util.concurrent.atomic.*;

public class Launcher {
	public static void main (String []args) throws Exception{
		
		int [][]m1 = new int [30][20];
		
		AtomicInteger [][]m2 = new AtomicInteger[30][20];
		
		RigaNaif [] rigaN = new RigaNaif[30];
		RigaTS [] rigaT = new RigaTS[30];
		ColonnaNaif [] colonnaN = new ColonnaNaif[20];
		ColonnaTS [] colonnaT = new ColonnaTS[20];
		
		
		for(int i = 0; i<m2.length; i++)
			for(int j = 0; j<m2[i].length; j++)
				m2[i][j] = new AtomicInteger(0);
		
		
		
		for(int i = 0; i<m1.length; i++){
			rigaN[i] = new RigaNaif(m1,i);
			
			rigaT[i] = new RigaTS(m2,i);
		
		}
		
		for(int j = 0; j<m1[1].length; j++){
			
			colonnaN[j] = new ColonnaNaif(m1,j);
		
			colonnaT[j] = new ColonnaTS(m2,j);
			
		}
		
		for(int i = 0; i<rigaN.length; i++){
			rigaN[i].start();
			rigaT[i].start();
			
		}
		
		for(int j = 0; j<m1[1].length; j++){
			colonnaT[j].start();
			colonnaN[j].start();
		}
		
		
		for(int j = 0 ; j<colonnaN.length; j++){
			colonnaN[j].join(); colonnaT[j].join();
		}
		
		for(int i = 0; i<rigaN.length; i++){
			rigaN[i].join(); 
			rigaT[i].join();
		}
		
		
		System.out.println("Matrice NAIF ");
		System.out.println();
		
		for(int i = 0; i<m1.length; i++)
			System.out.println(Arrays.toString(m1[i]));
		
		System.out.println("Matrice toga ");
		System.out.println();
	
		for(int i = 0; i<m2.length; i++)
			System.out.println(Arrays.toString(m2[i]));
	
	}
	
	
}

